<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

function realTimeProc(){
	$ci = & get_instance();
	$ci->tournament_entity->changeStatusTournamentRealTime();
	$ci->match_entity->changeStatusMatchRealTime();
	$ci->event_entity->changeStatusEventRealTime();
	$ci->event_category_entity->changeStatusEventCategoryRealTime();
	$ci->week_prize_entity->changeStatusPrizeWeekRealTime();
}

function isUserLogin(){
	$ci = & get_instance();
	return ($ci->session->userdata('account')) ? true:false;
}

function getUserId(){
	$ci = & get_instance();
	if($ci->session->userdata('account')){
		$array = $ci->session->userdata('account');
		return $array['id'];
	}
	return 0;
}

function changeValueOfMoney($value, $newCurrency, $oldCurrency){
	return (float) $value * ( (float) scoreCompareWithUSD($newCurrency) / scoreCompareWithUSD($oldCurrency) );	
}


function scoreCompareWithUSD($currency){
	$ci=& get_instance();
	$currencyArray = $ci->currency_entity->getListCurrency();
	$rate = 1; // USD is default
	foreach($currencyArray as $item){
		if( strtoupper($item->code) == strtoupper($currency)){
			$rate = $item->rate;
			break;
		}
	}
	return $rate;
}

function currencyExchangeScore($value, $currency){
	return format_Money($value, true);
}

function format_Money($number, $fractional=false) {  
    if ($fractional) { 
        $number = sprintf('%.2f', $number); 
    } 
    while (true) { 
        $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number); 
        if ($replaced != $number) { 
            $number = $replaced; 
        } else { 
            break; 
        } 
    } 
    return $number; 
} 

function bet_format($number){
	return sprintf('%.2f', $number); 
}

function sendSMS($foneNo, $body){
	$ch = curl_init();
	$user="vignesh@sunclassifiedads.com:india008";
	$receipientno= $foneNo; 
	$senderID="TEST SMS"; 
	$msgtxt= $body; 
	curl_setopt($ch,CURLOPT_URL,  "http://api.mVaayoo.com/mvaayooapi/MessageCompose");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&dcs=0&msgtxt=$msgtxt");
	$buffer = curl_exec($ch);
//	if(empty ($buffer))
//	{ echo " buffer is empty "; }
//	else
//	{ echo $buffer; } 
	curl_close($ch);
}


function sendSMS2($foneNo, $body){
	$ch = curl_init();
	$user="info@clicxa.com:india008";
	$receipientno= $foneNo; 
	$senderID="CLICXA"; 
	$msgtxt= $body; 
	curl_setopt($ch,CURLOPT_URL,  "http://api.mVaayoo.com/mvaayooapi/MessageCompose");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&senderID=$senderID&receipientno=$receipientno&dcs=0&msgtxt=$msgtxt&state=4");
	$buffer = curl_exec($ch);
//	if(empty ($buffer))
//	{ echo " buffer is empty "; }
//	else
//	{ echo $buffer; } 
	curl_close($ch);
	
	//http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=info@clicxa.com:india008&senderID=CLICXA&receipientno=9880228845&dcs=0&msgtxt=This is Test message&state=4 
}
